home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.lib.base_parent_interactor;
- import sub_arctic.lib.interactor;
- import sub_arctic.constraints.std_function;
- import sub_arctic.constraints.constraint;
- import sub_arctic.output.drawable;
- import sub_arctic.output.color_pair;
-
- /**
- * This object puts its children in a tiled row, from left to right. They
- * can be aligned along the TOP, CENTER, or BOTTOM.
- *
- * @author Scott Hudson
- */
- public class row extends base_parent_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * If this variable is set, the interactor has a box around it.
- */
- protected boolean _boxed=true;
-
- /**
- * Return whether or not the interactor has a box around it.
- * @return boolean true if the row has a box around it
- */
- public boolean boxed() { return _boxed;};
-
- /**
- * Control whether or not the interactor has a box around it.
- *@param boolean b new state of boxedness
- */
- public void set_boxed(boolean b) {
- _boxed=b;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This holds our state variable about whether or not we are
- * sized by our children. This variable can only be set at
- * construction time.
- */
- protected boolean _size_by_children=true;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This holds the color pair in use for this object. null indicates
- * to use the system default color pair.
- */
- protected color_pair _colors;
-
- /**
- * Return the current color pair. If you get null, we are using the
- * system's default color pair. Note that the color pair for this
- * interactor is <STRONG>not</STRONG> consulted if the object is
- * not opaque.
- *
- * @return color_pair the current color pair
- */
- public color_pair colors() {
- if (_colors!=null) {
- return _colors;
- } else {
- return manager.default_color_pair();
- }
- }
-
- /**
- * Set the current color pair. If you set this to null, you'll get
- * the system default color pair.
- * @param color_pair cp the new color_pair for this interactor
- */
- public void set_colors(color_pair cp) {
- _colors=cp;
- damage_self();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * If this variable is set, the interactor has an opaque background.
- */
- protected boolean _opaque=true;
-
- /**
- * Return whether or not the interactor has an opaque background
- * @return boolean true if the row is opaque
- */
- public boolean opaque() { return _opaque;};
-
- /**
- * Control whether or not the interactor has an opaque background
- * @param boolean b new state of opaqueness
- */
- public void set_opaque(boolean b) {
- _opaque=b;
- damage_self();
- }
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Border (whitespace) around all the children. */
- protected int _border;
-
- /** Return the border around all the children (in pixels).
- * @return int the size of the border in pixels */
- public int border() {return _border;}
-
- /** Set border all around the children.
- * @param int v the size of the border around the children in pixels
- */
- public void set_border(int v)
- {
- /* set the value then incorporate that back into constraints */
- _border = v;
- set_child_constraints();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** The spacing between children. */
- protected int _interchild_space;
-
- /**
- * return the spacing between children.
- * @return int the space between the children in the row (in pixels)
- */
- public int interchild_space() {return _interchild_space;}
-
- /** Set the spacing between children.
- *@param int v the new interchild spacing
- */
- public void set_interchild_space(int v)
- {
- /* set the value then incorporate that back into constraints */
- _interchild_space = v;
- set_child_constraints();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Constant to denote centered layout. */
- public static final byte CENTER_JUSTIFIED = 0;
-
- /** Constant to denote left justified layout. */
- public static final byte TOP_JUSTIFIED = 1;
-
- /** Constant to denote right justified layout */
- public static final byte BOTTOM_JUSTIFIED = 2;
-
- /** The layout type for this row. */
- protected byte _layout_type;
-
- /**
- * The layout type for this row.
- * @return byte the type of layout in use in this interactor (must be one
- * of the constants CENTER_JUSTIFIED, TOP_JUSTIFIED,
- * BOTTOM_JUSTIFIED).
- */
- public byte layout_type() {return _layout_type;}
-
- /**
- * Set the layout type for this row.
- * @param byte v the type of layout you want (must be one of the constants
- * CENTER_JUSTIFIED, TOP_JUSTIFIED, BOTTOM_JUSTIFIED).
- */
- public void set_layout_type(byte v)
- {
- /* verify layout type */
- if ((v != CENTER_JUSTIFIED) && (v != TOP_JUSTIFIED) &&
- (v != BOTTOM_JUSTIFIED))
- {
- throw new sub_arctic_error(
- "Unrecognized layout type ("+v+") in set_layout_type()");
- }
-
- /* set the value then incorporate that back into constraints */
- _layout_type = v;
- set_child_constraints();
- }
-
- //had:
- //* @exception bad_value this is thrown if you give a bad constant
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor for row.
- * @param int xv the x position of this interactor.
- * @param int yv the y position of this interactor.
- * @param int wv the width of this interactor.
- * @param int hv the height of this interactor.
- * @param int b the border around the children of this row.
- * @param int ic the inter-child spacing for this row.
- * @param boolean box whether or not you want a box around this interactor.
- * @param boolean o whether or not the object has an opaque background.
- * @param boolean sbc size by children (true if you want this object to
- * derive its size from its children).
- * @param byte b the type of layout you want for this row (must be
- * one of the constants CENTER_JUSTIFIED,
- * TOP_JUSTIFIED, BOTTOM_JUSTIFIED).
- * @param color_pair cp the color pair to use if this object is opaque (if
- * you use null here you'll get the system's default
- * color pair).
- */
- public row(
- int xv, int yv,
- int wv, int hv,
- int b, int ic,
- boolean box,
- boolean o,
- boolean sbc,
- byte lt,
- color_pair cp)
- {
- super(xv,yv,wv,hv);
-
- /* stash values */
- _border = b;
- _opaque= o;
- _interchild_space = ic;
- _boxed=box;
- _colors=cp;
- _size_by_children=sbc;
-
- /* verify layout type */
- if ((lt != CENTER_JUSTIFIED) && (lt != TOP_JUSTIFIED) &&
- (lt != BOTTOM_JUSTIFIED))
- {
- throw new sub_arctic_error("Unrecognized layout type ("+lt+") in row()");
- }
- _layout_type = lt;
- }
-
- //had:
- //* @exception bad_value if unrecognized layout type is requested.
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Smaller row constructor. This assumes that you want to just set the
- * actual parameters of the row and you will use constraints to do all
- * sizing & positioning. It uses the system's default colors for
- * opaque backgrounds.
- *
- * @param int b the border around the children of this row.
- * @param int ic the inter-child spacing for this row.
- * @param boolean box whether or not you want a box around this interactor.
- * @param boolean o whether or not the object is opaque.
- * @param byte b the type of layout you want for this row (must be one
- * of the constants CENTER_JUSTIFIED, TOP_JUSTIFIED,
- * BOTTOM_JUSTIFIED).
- */
- public row(int b, int ic, boolean box, boolean o, byte lt)
- {
- super(0,0,10,10);
-
- /* stash values */
- _border = b;
- _opaque= o;
- _boxed=box;
- _interchild_space = ic;
- _colors=null;
-
- /* verify layout type */
- if ((lt != CENTER_JUSTIFIED) && (lt != TOP_JUSTIFIED) &&
- (lt != BOTTOM_JUSTIFIED))
- {
- throw new sub_arctic_error("Unrecognized layout type ("+lt+") in row()");
- }
- _layout_type = lt;
- }
-
- //had:
- //* @exception bad_value if unrecognized layout type is requested.
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Minimal row constructor. This assumes that you want to use
- * constraints for size & position. It makes the row not have a
- * border and be opaque and have no whitespace border around
- * its edges. It uses the system default colors.
- *
- * @param int ic the inter-child spacing for this row.
- * @param byte b the type of layout you want for this row (must be one of
- * the constants CENTER_JUSTIFIED, TOP_JUSTIFIED,
- * BOTTOM_JUSTIFIED).
- */
- public row(int ic, byte lt)
- {
- super(0,0,10,10);
-
- /* stash values */
- _border = 0;
- _opaque= true;
- _boxed= false;
- _interchild_space = ic;
- _colors=null;
-
- /* verify layout type */
- if ((lt != CENTER_JUSTIFIED) && (lt != TOP_JUSTIFIED) &&
- (lt != BOTTOM_JUSTIFIED))
- {
- throw new sub_arctic_error("Unrecognized layout type ("+lt+") in row()");
- }
- _layout_type = lt;
- }
-
- //had:
- //* @exception bad_value if unrecognized layout type is requested.
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set up the constraint for this object's width and height.
- */
- public void set_local_constraints()
- {
- constraint width_constraint, height_constraint;
-
- /* if we are not sized by our children, then just don't do anything */
- if (!_size_by_children) {
- return;
- }
-
- /* now set up the width and height constraints of this object */
- /* width is sum of width of children + border */
- /* note: this is NOT 2*border because we took one of them into account */
- /* when laying out the first child's x position */
- width_constraint=std_function.offset(LAST_CHILD.X2(),border());
-
- /* height is max height + 2*border */
- height_constraint=std_function.offset(MAX_CHILD.H(),2*border());
-
- /* snap them on */
- set_w_constraint(width_constraint);
- set_h_constraint(height_constraint);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Establish or reestablish constraints on children to form a row.
- */
- protected void set_child_constraints()
- {
- int i, max = num_children();
- interactor current_child;
- constraint strut_between_children, yposition = null;
-
- /* loop over all children */
- for (i=0; i<max; ++i)
- {
- /* set the current child */
- current_child = child(i);
-
- /* constraint syntax is: object code, part code, fun code, parm */
-
- /* set up the strut between children */
- if (i != 0)
- {
- /* this is the strut which keeps the y position of a child
- * below the previous child */
- strut_between_children = std_function.offset(PREV_SIBLING.X2(),
- interchild_space());
- current_child.set_x_constraint(strut_between_children);
- }
- else
- {
- /* i is zero, setup the top constraint */
- strut_between_children = std_function.offset(PARENT.X(), border());
- current_child.set_x_constraint(strut_between_children);
- }
-
- /* build y constraint based on layout type */
- if (layout_type() == CENTER_JUSTIFIED)
- yposition=std_function.centered(PARENT.H(), 0);
- else if (layout_type() == TOP_JUSTIFIED)
- yposition = std_function.offset(PARENT.Y(), border());
- else if (layout_type() == BOTTOM_JUSTIFIED)
- yposition = std_function.far_edge_just(PARENT.Y2(), border());
-
- /* set the constraint */
- current_child.set_y_constraint(yposition);
- }
-
- /* set this object's own constraints */
- set_local_constraints();
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the object on the provided drawable
- * @param drawable d the surface to draw on
- */
- protected void draw_self_local(drawable d)
- {
- /* clear the background */
- if (opaque()) {
- d.setColor(colors().background());
- d.fillRect(0,0,w()-1,h()-1);
- }
- /* draw a bounding box */
- if (boxed()) {
- d.drawRect(0, 0, w()-1, h()-1);
- }
- draw_children(d);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Overridden from base_interactor to also add constraints
- * @param int at_indx the index position at which to change the child
- * @param interactor chld the new child interactor for that position
- */
- public void set_child(int at_indx, interactor chld)
- {
- super.set_child(at_indx,chld);
- set_child_constraints();
- }
-
- //had:
- //* @exception op_not_supported PROPAGATED
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Override from base_interactor to also add constraints
- * @param interactor chld the child interactor to add
- */
- public void add_child(interactor chld)
- {
- super.add_child(chld);
- set_child_constraints();
- }
-
- //had:
- //* @exception op_not_supported PROPAGATED
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override to also add constraints
- * @param int at_indx the index position at which to insert the child
- * @param interactor chld the child interactor to insert
- */
- public void insert_child(int at_indx, interactor chld)
- {
- super.insert_child(at_indx,chld);
- set_child_constraints();
- }
-
- //had:
- //* @exception op_not_supported PROPAGATED
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override to also add constraints
- * @param int at_indx the index position of the child to remove
- */
- public interactor remove_child(int at_indx)
- {
- interactor i;
-
- i=super.remove_child(at_indx);
- set_child_constraints();
- return i;
- }
-
- //had:
- //* @exception op_not_supported PROPAGATED
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override to also add constraints
- * @param interactor the_child the child to remove
- */
- public void remove_child(interactor the_child)
- {
- super.remove_child(the_child);
- set_child_constraints();
- }
-
- //had:
- //* @exception op_not_supported PROPAGATED
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-